#!/bin/bash
set -e
# for single cell



while getopts  ":p:" opts
do
        case  $opts  in
		p)
		out_prefix=$OPTARG
		;;
        esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then
	echo `basename $0` '[-p out_prefix] reads1.fq[.gz], reads2.fq[.gz]'
	exit 1
fi

#-----------------------------------------------
#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------



# cutadapt=${tools_path}/cutadapt-1.8.1/bin/cutadapt

truseq_uni=AATGATACGGCGACCACCGAGATCTACACTCTTTCCCTACACGACGCTCTTCCGATCT

truseq_uni_res_com=AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATCTCGGTGGTCGCCGTATCATT

truseq_uni_res_com_22=AGATCGGAAGAGCGTCGTGTAG
truseq_uni_res_com_20=AGATCGGAAGAGCGTCGTGT

truseq_0=GATCGGAAGAGCACACGTCTGAACTCCAGTCAC
truseq_1=ATCTCGTATGCCGTCTTCTGCTTG

truseq1=${truseq_0}${barcode}${truseq_1}

truseq_0_22=GATCGGAAGAGCACACGTCTGA
truseq_0_20=GATCGGAAGAGCACACGTCT

primer5maltic=GTGAGTGATGGTTGAGGTAGTGTGGAG
primer5maltic20=ATGGTTGAGGTAGTGTGGAG

primer3maltic=CTCCACACTACCTCAACCATCACTCAC
primer3maltic20=CTCCACACTACCTCAACCAT

smart5=AAGCAGTGGTATCAACGCAGAGTAC
smart3=GTACTCTGCGTTGATACCACTGCTT

smart5_20=GTGGTATCAACGCAGAGTAC
smart3_20=CTGCGTTGATACCACTGCTT



# $cutadapt \
# -n 2 \
# -q 10 \
# --trimmed-only \
# -m 65 \
# -M 200 \
# -a $truseq_0_20 \
# -A $truseq_uni_res_com_20 \
# -o $s1.cut.fastq \
# -p $s2.cut.fastq \
# $1 \
# $2 \
# 2>>$log 1>&2

# $cutadapt \
# -n 2 \
# -q 10 \
# -m 65 \
# -M 200 \
# -a $truseq_0_20 \
# -A $truseq_uni_res_com_20 \
# -o $s1.cut.fastq \
# -p $s2.cut.fastq \
# $1 \
# $2 \
# 2>>$log 1>&2

# cut general smart malbac
# first general to reduce data
# second smart to cut smart or (smart and malbac)


${tools_path}/Python-2.7.10/python \
$cutadapt \
-e 0.12 \
--overlap 5 \
-n 2 \
-a $truseq_0_20 \
-A $truseq_0_20 \
-o $out_prefix.1.general.fastq \
-p $out_prefix.2.general.fastq \
$1 \
$2

${tools_path}/Python-2.7.10/python \
$cutadapt \
-e 0.12 \
--overlap 5 \
-n 2 \
-a $smart3_20 \
-A $smart3_20 \
-g $smart5_20 \
-G $smart5_20 \
-o $out_prefix.1.smart.fastq \
-p $out_prefix.2.smart.fastq \
$out_prefix.1.general.fastq \
$out_prefix.2.general.fastq

${tools_path}/Python-2.7.10/python \
$cutadapt \
-m 30 \
-e 0.12 \
--overlap 5 \
-n 2 \
-a $primer3maltic20 \
-A $primer3maltic20 \
-g $primer5maltic \
-G $primer5maltic \
-o $out_prefix.1.malbac.fastq \
-p $out_prefix.2.malbac.fastq \
$out_prefix.1.smart.fastq \
$out_prefix.2.smart.fastq



# $cutadapt \
# -u +20 \
# -u -20 \
# -U +20 \
# -U -20 \
# -m 20 \
# -o $s1.trimmed.fastq \
# -p $s2.trimmed.fastq \
# $s1.cut.fastq \
# $s2.cut.fastq \
# 2>>$log 1>&2

# len5=21
# len3=25

# $cutadapt \
# -u +$len5 \
# -u -$len3 \
# -U +$len5 \
# -U -$len3 \
# -o $out_prefix.1.trimmed.fastq \
# -p $out_prefix.2.trimmed.fastq \
# $out_prefix.1.cut.fastq \
# $out_prefix.2.cut.fastq \
# 2>>$log 1>&2

